package com.zhou.service.impl.event;


import com.zhou.dto.IdentityInfo;
import com.zhou.repository.IdentityInfoDataRepository;
import com.zhou.service.WxEventStrategy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author lcz
 * @desc 取消订阅策略
 * @mail lcz_0130@163.com
 * @date 2023/12/28
 */

@Service("unsubscribe")
@Slf4j
public class UnsubscribeStrategy implements WxEventStrategy {
    @Resource
    private IdentityInfoDataRepository identityInfoDataRepository;


    @Override
    public void execute(Map<String, String> requestMap, HttpServletResponse response) throws Exception {
        log.info("事件类型：unsubscribe");
        // 获取取消订阅者信息
        log.info("用户取消订阅！");
        log.info(">>> 用户取消订阅！");
        // 数据库中状态修改
        String openId = requestMap.get("FromUserName");
        // 修改status为1
        IdentityInfo byOpenId = identityInfoDataRepository.findByOpenId(openId);
        byOpenId.setUserStatus(1);
        identityInfoDataRepository.save(byOpenId);
    }
}
